home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Science / MathPad 2.1.5 / examples / vector ops < prev    next >
Text File  |  1993-06-13  |  816b  |  25 lines

  1. -- Arrays can be used to represent vectors. Addition, subtraction and multiplication by a scalar can be done directly. The following functions implement other basic vector operations.
  2.  
  3. dot(A,B) = sum(A[i]*B[i],i,1,count(A))
  4.  
  5. magnitude(A) = sqrt(dot(A,A))
  6.  
  7. cross(A,B) = {A[2]*B[3]-A[3]*B[2],
  8.               A[3]*B[1]-A[1]*B[3],
  9.               A[1]*B[2]-A[2]*B[1]}
  10.  
  11. -- cartesian to spherical coordinates
  12. spherical(A) = {magnitude(A),
  13.                 acos(A[3]/magnitude(A)),
  14.                 atan2(A[2],A[1])}
  15.  
  16. -- spherical to cartesian coordinates
  17. cartesian(r,theta,phi) = {r*sin(theta)*cos(phi),
  18.                           r*sin(theta)*sin(phi),
  19.                           r*cos(theta) }
  20.  
  21. atan2(y,x) = 0 when x=0 and y=0,
  22.              atan(y/x) when x>=0,
  23.              atan(y/x)+180 when y>=0,
  24.              atan(y/x)-180
  25.